a=int(input())
b=[]
c=-5
if a!=0:
    while a!=0:
        b.append(a)
        a=input()
        if int(a)==0:
            break
    d=len(b)
    if d>=5:
        d=d-5
        for e in b[d:]:
            print(e,end=' ')
    else:
        for e in b:
            print(e,end=' ')
